package com.example.moilapp.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.example.moilapp.Moil_DO;
import com.example.moilapp.Moil_Job_Detail;
import com.example.moilapp.R;
import com.example.moilapp.global.Moil_Array_To_List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Moil_DO_Service extends AsyncTask<String, Void, String> {

	private ProgressDialog progdialod;
	private Activity activity;
	private Context context;
	
	public static final String PREFS_NAME = "PrefsFile";

	private ListView passLstview;

	// connection establish timeout (timeoutConnection)
	private int timeoutConnection = 5000;
	// socket timeout (timeoutSocket)
	private int timeoutSocket = 45000;

	private static byte[] buff = new byte[1024];
	private String retval = "";

	private ArrayAdapter<String> listAdapter;
	
	private ViewBaseAdap listAdapter_address;
	
	public String complete = "Completed";
	public String acknowledged = "Acknowledged";
	public String created = "Created";

	private String[] app_ids;

	private String Vassel;
	private int position;
	private String[] JobId;
	private String[] addresss;
	private String pass_title;
	private String picno;
	
	private String[] address_actual;

	private String[] app_job_no;
	private String[] app_dono;
	private String[] app_date;
	private String[] app_prdby;
	private String[] app_totpak;
	private String[] app_billto;
	private String[] app_shipto;
	private String[] app_mawb;
	private String[] app_hawb;
	private String[] app_flt;
	private String[] app_arrdate;
	private String[] app_origin;
	private String[] app_nopkg;
	private String[] app_weight;
	private String[] app_vessel;
	private String[] app_shipper;
	private String[] app_des_goods;
	private String[] app_delAddr;
	private String[] app_OrderAddr;

	private String[] app_finalstr;

	private static final String SOAP_ACTION = "http://tempuri.org/GetJobInfoBySerial";

	private static final String METHOD_NAME = "GetJobInfoBySerial";

	private static final String NAMESPACE = "http://tempuri.org/";
	private static final String URL = "http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx";
	protected static final String TAG = null;
	
	boolean isLast;

	public Moil_DO_Service(Activity activity, String Vassel, String[] JobId,String[] addresss,int position,boolean isLast,String pass_title,String picno) {
		super();
		this.activity = activity;
		this.context = this.activity.getApplicationContext();
		this.Vassel = Vassel;
		this.JobId = new String[JobId.length];
		this.JobId = JobId;
		this.isLast = isLast;
		this.position = position;
		this.addresss = new String[addresss.length];
		this.addresss = addresss;
		this.pass_title = pass_title;
		this.picno = picno;
		
		for(int adrloop=0;adrloop<addresss.length;adrloop++){
			Log.e("addresss[adrloop] in Contructor", ""+addresss[adrloop]);
		}
		
		/*for(int loop = 0;loop<JobId.length;loop++){
			Log.e("JobId valuess", ""+JobId[loop]);
		}*/
		
		Log.e("position", ""+position);
		Log.e("JobId.length", ""+JobId.length);
		Log.e("JobId value", ""+JobId[position-1]);
		
		Log.e("addresss.length", ""+addresss.length);
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		progdialod = ProgressDialog.show(this.activity, "Search", "Updating",
				true, false);
	}

	@Override
	protected String doInBackground(String... urls) {

		try {

			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			String[] job_serial_date = JobId[position-1].split("~");
			
			Log.e("job_serial_date[0]", job_serial_date[0]);
			Log.e("job_serial_date[1]", job_serial_date[1]);
			Log.e("job_serial_date[2]", job_serial_date[2]);
			
			request.addProperty("jobID", job_serial_date[0]);
			request.addProperty("SerialID", (int) Math.round(Double.parseDouble(job_serial_date[1])));
			request.addProperty("Date", job_serial_date[2]);

			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.dotNet = true;
			envelope.setOutputSoapObject(request);

			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, envelope);

			SoapPrimitive resultSoapPrimitive;
			resultSoapPrimitive = (SoapPrimitive) envelope.getResponse();

			String result = resultSoapPrimitive.toString();

			retval = result;

			Log.d("return", retval);

			return retval;

		} catch (Exception e) {

		}
		return retval;

	}

	@Override
	protected void onPostExecute(String result) {
		int loopcount;

		Log.v("result", result);
		
		progdialod.dismiss();

		try {

			JSONObject fullThing = new JSONObject(result);
			
			String TW_Address = fullThing.getString("TW_Address");

			JSONArray TW_Traffic_detail = fullThing
					.getJSONArray("TW_Traffic_detail");

			app_ids = new String[TW_Traffic_detail.length()];
			app_finalstr = new String[TW_Traffic_detail.length()];
			app_job_no = new String[TW_Traffic_detail.length()];
			app_dono = new String[TW_Traffic_detail.length()];
			app_date = new String[TW_Traffic_detail.length()];
			app_prdby = new String[TW_Traffic_detail.length()];
			app_totpak = new String[TW_Traffic_detail.length()];
			app_billto = new String[TW_Traffic_detail.length()];
			app_shipto = new String[TW_Traffic_detail.length()];
			app_mawb = new String[TW_Traffic_detail.length()];
			app_hawb = new String[TW_Traffic_detail.length()];
			app_flt = new String[TW_Traffic_detail.length()];
			app_arrdate = new String[TW_Traffic_detail.length()];
			app_origin = new String[TW_Traffic_detail.length()];
			app_nopkg = new String[TW_Traffic_detail.length()];
			app_weight = new String[TW_Traffic_detail.length()];
			app_vessel = new String[TW_Traffic_detail.length()];
			app_shipper = new String[TW_Traffic_detail.length()];
			app_des_goods = new String[TW_Traffic_detail.length()];
			app_delAddr = new String[TW_Traffic_detail.length()];
			app_OrderAddr = new String[TW_Traffic_detail.length()];

			for (int i = 0; i < TW_Traffic_detail.length(); i++) {
				JSONObject TW_Traffic_detail_2 = TW_Traffic_detail
						.getJSONObject(i);

				JSONObject TW_Traffic_detail_3 = TW_Traffic_detail_2
						.getJSONObject("TW_Traffic_detail");

				// PRIYAN

				int Job_id = TW_Traffic_detail_3.getInt("job_id");
				String Job_No = TW_Traffic_detail_3.getString("job_no");
				String Job_date = TW_Traffic_detail_3.getString("job_date");
				String Do_No = TW_Traffic_detail_3.getString("do_no");
				// String Organization =
				// TW_Traffic_detail_3.getString("Organization");
				int Addr_seq = TW_Traffic_detail_3.getInt("sequence_dtl");
				// String Addr1 = TW_Traffic_detail_3.getString("Addr1");
				// String Addr2 = TW_Traffic_detail_3.getString("Addr2");
				// String Addr3 = TW_Traffic_detail_3.getString("Addr3");
				// String Addr4 = TW_Traffic_detail_3.getString("Addr4");
				// String Telephone =
				// TW_Traffic_detail_3.getString("Telephone");
				// String Fax = TW_Traffic_detail_3.getString("Fax");
				int PackageCount = TW_Traffic_detail_3.getInt("packages");
				// String Shipping_addr1 =
				// TW_Traffic_detail_3.getString("Shipping_addr1");
				// String Shipping_addr2 =
				// TW_Traffic_detail_3.getString("Shipping_addr2");
				String Mawb_bl = TW_Traffic_detail_3.getString("mawb_bl");
				String arrival_date = TW_Traffic_detail_3
						.getString("arrival_date");
				String Weight = TW_Traffic_detail_3.getString("weight");
				String Description = TW_Traffic_detail_3
						.getString("good_description");
				// String Destination =
				// TW_Traffic_detail_3.getString("Destination");
				// String FirstName =
				// TW_Traffic_detail_3.getString("FirstName");
				// String VessalName =
				// TW_Traffic_detail_3.getString("VessalName");
				// String Order_number =
				// TW_Traffic_detail_3.getString("Order_number");

				// PRIYAN

				String TW_PreparedBy = TW_Traffic_detail_2
						.getString("TW_PreparedBy");
				String TW_From = TW_Traffic_detail_2.getString("TW_From");
				String TW_To = TW_Traffic_detail_2.getString("TW_To");
				

				app_ids[i] = ""+Job_id;
				app_job_no[i] = Job_No;
				app_dono[i] = Do_No;
				app_date[i] = Job_date;
				app_prdby[i] = TW_PreparedBy;
				app_totpak[i] = ""+PackageCount;
				app_billto[i] = TW_From;
				//app_shipto[i] = TW_To;
				app_shipto[i] = Description;
				app_mawb[i] = Mawb_bl;
				app_hawb[i] = "NA";
				app_flt[i] = "NA";
				app_hawb[i] = "NA";
				app_flt[i] = "NA";
				app_arrdate[i] = arrival_date;
				//app_origin[i] = "NA";
				app_origin[i] = TW_From+" / "+TW_To;
				app_nopkg[i] = ""+PackageCount;
				app_weight[i] = Weight;
				app_vessel[i] = Vassel;
				app_shipper[i] = "NA";
				app_shipper[i] = "NA";
				app_des_goods[i] = Description;
				/*app_delAddr[i] = TW_To;
				app_OrderAddr[i] = TW_From;*/
				app_delAddr[i] = TW_Address;
				app_OrderAddr[i] = TW_Address;
				app_finalstr[i] = "JOB NO. : " + Job_No + " Do NUMBER : "
						+ Do_No;
			}
			
			
			///PUT IN
			
			//Moil_Array_To_List.reSet();
			Moil_Array_To_List.addToDataHash("app_ids", app_ids);
			Moil_Array_To_List.addToDataHash("app_finalstr", app_finalstr);
			Moil_Array_To_List.addToDataHash("app_OrderAddr", app_OrderAddr);
			Moil_Array_To_List.addToDataHash("app_job_no", app_job_no);
			Moil_Array_To_List.addToDataHash("app_dono", app_dono);
			Moil_Array_To_List.addToDataHash("app_date", app_date);
			Moil_Array_To_List.addToDataHash("app_totpak", app_totpak);
			Moil_Array_To_List.addToDataHash("app_billto", app_billto);
			Moil_Array_To_List.addToDataHash("app_shipto", app_shipto);
			Moil_Array_To_List.addToDataHash("app_mawb", app_mawb);
			Moil_Array_To_List.addToDataHash("app_hawb", app_hawb);
			Moil_Array_To_List.addToDataHash("app_arrdate", app_arrdate);
			Moil_Array_To_List.addToDataHash("app_origin", app_origin);
			Moil_Array_To_List.addToDataHash("app_nopkg", app_nopkg);
			Moil_Array_To_List.addToDataHash("app_weight", app_weight);
			Moil_Array_To_List.addToDataHash("app_vessel", app_vessel);
			Moil_Array_To_List.addToDataHash("app_shipper", app_shipper);
			Moil_Array_To_List.addToDataHash("app_des_goods", app_des_goods);
			Moil_Array_To_List.addToDataHash("app_delAddr", app_delAddr);
			

			///PUT IN
			

		} catch (JSONException e) {
			//e.printStackTrace();
			Log.e("JSONException", e.toString());
		}
		
		
		
		if(isLast){
			
			ListView passLstview_address = (ListView) activity.findViewById(R.id.list_address);
			
			passLstview_address.setOverScrollMode(View.OVER_SCROLL_NEVER);
				
				List<String> allConnected = new ArrayList<String>();
				
				Log.e("addresss.length before for loop", ""+addresss.length);
				Log.e("addresss[0]", ""+addresss[0]);
				Log.e("addresss[1]", ""+addresss[1]);
				
				for(int adrloop=0;adrloop<addresss.length;adrloop++){
					Log.e("addresss[adrloop] for loop aDDFRESS", ""+addresss[adrloop]);
				}
				
				for(int adrloop=0;adrloop<addresss.length;adrloop++){
					String[] arrSepDelPick = addresss[adrloop].split("~");
					
					Log.e("addresss[adrloop]", addresss[adrloop]);
					Log.e("arrSepDelPick.length", ""+arrSepDelPick.length);
					for(int i=0;i<arrSepDelPick.length;i++){
						Log.e("arrSepDelPick[i]", arrSepDelPick[i]);
						if(!arrSepDelPick[i].equals("")){
							allConnected.add(arrSepDelPick[i]);
						}

				    } 
				}
				
				address_actual = allConnected.toArray(new String[allConnected.size()]);
				
				//listAdapter_address = new ViewBaseAdap(activity.getApplicationContext());
				
			if (address_actual != null) {

				passLstview_address.setAdapter(new ViewBaseAdap(activity,address_actual));

			}
		
			ListView passLstview = (ListView) activity.findViewById(R.id.list_do);
			
			
			getAllBack();
	
			if (app_finalstr != null) {
	
				Log.e("app_finalstr", "" + app_finalstr.length);
				
	
				listAdapter = new ArrayAdapter<String>(activity, R.layout.moil_row,
						app_finalstr);
				passLstview.setAdapter(listAdapter);
				
				listAdapter.notifyDataSetChanged();
	
				passLstview.setOnItemClickListener(new OnItemClickListener() {
	
					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int location, long id) {
	
						if(!app_dono[location].equals("")){
							final Intent intent = new Intent(context,
									Moil_Job_Detail.class);
							intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
							Bundle bundle = new Bundle();
		
							bundle.putInt("jobid", Integer.parseInt(app_ids[location]));
							bundle.putString("orgname", app_finalstr[location]);
							bundle.putString("OrderAddr", app_OrderAddr[location]);
							bundle.putString("jobno", app_job_no[location]);
							bundle.putString("dono", app_dono[location]);
							bundle.putString("date", app_date[location]);
							bundle.putString("pageno", "1");
							bundle.putString("prpby", "PS");
							bundle.putInt("totpack", Integer.parseInt(app_totpak[location]));
							bundle.putString("billto", app_billto[location]);
							bundle.putString("shipto", app_shipto[location]);
							bundle.putString("mawb", app_mawb[location]);
							bundle.putString("hawb", app_hawb[location]);
							bundle.putString("flt", "NA");
							bundle.putString("arrdate", app_arrdate[location]);
							bundle.putString("origin", app_origin[location]);
							bundle.putInt("nopack", Integer.parseInt(app_nopkg[location]));
							bundle.putString("weight", app_weight[location]);
							bundle.putString("vessel", app_vessel[location]);
							bundle.putString("shipper", app_shipper[location]);
							bundle.putString("desgoods", app_des_goods[location]);
							bundle.putString("deladdr", app_delAddr[location]);
							bundle.putString("clientName", pass_title);
							bundle.putString("pic", picno);
		
							intent.putExtras(bundle);
							context.startActivity(intent);
						}else{
							Toast.makeText(context,"DO Numebr Empty!!",Toast.LENGTH_SHORT).show();
						}
					}
	
				});
			}
		}else{
			//ABOUT TO LOOP LIKE HELL
			Moil_DO_Service mps = new Moil_DO_Service(activity,Vassel,JobId,addresss,position+1,((JobId.length-1)==(position))?true:false,pass_title,picno);
	    	mps.execute(new String[] {"http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx"});
	    	//ABOUT TO LOOP LIKE HELL
		}

	}

	public String fixDate(String inputDate) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = sdf.parse(inputDate);
		} catch (ParseException | java.text.ParseException e) {
			e.printStackTrace();
		}
		sdf = new SimpleDateFormat("MMM dd, yyyy");
		String MMdd = sdf.format(date);

		Log.e("Formated Date", MMdd);

		return MMdd;
	}
	
	private void getAllBack(){

		app_ids = new String[Moil_Array_To_List.getDataHashItem("app_ids").length];
		app_ids = Moil_Array_To_List.getDataHashItem("app_ids");
		app_finalstr = new String[Moil_Array_To_List.getDataHashItem("app_finalstr").length];
		app_finalstr = Moil_Array_To_List.getDataHashItem("app_finalstr");
		app_OrderAddr = new String[Moil_Array_To_List.getDataHashItem("app_OrderAddr").length];
		app_OrderAddr = Moil_Array_To_List.getDataHashItem("app_OrderAddr");
		app_job_no = new String[Moil_Array_To_List.getDataHashItem("app_job_no").length];
		app_job_no = Moil_Array_To_List.getDataHashItem("app_job_no");
		app_dono = new String[Moil_Array_To_List.getDataHashItem("app_dono").length];
		app_dono = Moil_Array_To_List.getDataHashItem("app_dono");
		app_date = new String[Moil_Array_To_List.getDataHashItem("app_date").length];
		app_date = Moil_Array_To_List.getDataHashItem("app_date");
		app_totpak = new String[Moil_Array_To_List.getDataHashItem("app_totpak").length];
		app_totpak = Moil_Array_To_List.getDataHashItem("app_totpak");
		app_billto = new String[Moil_Array_To_List.getDataHashItem("app_billto").length];
		app_billto = Moil_Array_To_List.getDataHashItem("app_billto");
		app_shipto = new String[Moil_Array_To_List.getDataHashItem("app_shipto").length];
		app_shipto = Moil_Array_To_List.getDataHashItem("app_shipto");
		app_mawb = new String[Moil_Array_To_List.getDataHashItem("app_mawb").length];
		app_mawb = Moil_Array_To_List.getDataHashItem("app_mawb");
		app_hawb = new String[Moil_Array_To_List.getDataHashItem("app_hawb").length];
		app_hawb = Moil_Array_To_List.getDataHashItem("app_hawb");
		app_arrdate = new String[Moil_Array_To_List.getDataHashItem("app_arrdate").length];
		app_arrdate = Moil_Array_To_List.getDataHashItem("app_arrdate");
		app_origin = new String[Moil_Array_To_List.getDataHashItem("app_origin").length];
		app_origin = Moil_Array_To_List.getDataHashItem("app_origin");
		app_nopkg = new String[Moil_Array_To_List.getDataHashItem("app_nopkg").length];
		app_nopkg = Moil_Array_To_List.getDataHashItem("app_nopkg");
		app_weight = new String[Moil_Array_To_List.getDataHashItem("app_weight").length];
		app_weight = Moil_Array_To_List.getDataHashItem("app_weight");
		app_vessel = new String[Moil_Array_To_List.getDataHashItem("app_vessel").length];
		app_vessel = Moil_Array_To_List.getDataHashItem("app_vessel");
		app_shipper = new String[Moil_Array_To_List.getDataHashItem("app_shipper").length];
		app_shipper = Moil_Array_To_List.getDataHashItem("app_shipper");
		app_des_goods = new String[Moil_Array_To_List.getDataHashItem("app_des_goods").length];
		app_des_goods = Moil_Array_To_List.getDataHashItem("app_des_goods");
		app_delAddr = new String[Moil_Array_To_List.getDataHashItem("app_delAddr").length];
		app_delAddr = Moil_Array_To_List.getDataHashItem("app_delAddr");
		
	}
	
	class ViewBaseAdap extends ArrayAdapter{
		
		 private Context context;
		 LayoutInflater inflater;

		public ViewBaseAdap(Activity activity,String[] titles) {
			super(activity, R.layout.moil_row_white,R.id.txt_pickup_data,address_actual);
			this.context = activity.getApplicationContext();
			//this.inflater = LayoutInflater.from(context);
			
		}
		
		@Override
		public View getView(int position,View convertView,ViewGroup parent){
			
			final ViewHolder holder;
			final String title;
			final String serial;
			final String date;
			final String pickup_delivery;
			final int pos;
			
			SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
			final SharedPreferences.Editor editor = settings.edit();
			
			if (convertView == null) {
			   LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
               convertView = li.inflate(R.layout.moil_row_white, parent, false);
               
               holder = new ViewHolder();
               holder.textView = (TextView)convertView.findViewById(R.id.txt_pickup_data);
               holder.textView_title = (TextView)convertView.findViewById(R.id.txt_pickup_title);
               holder.textPic = (TextView)convertView.findViewById(R.id.txt_pic_title);
               holder.textPic_data = (TextView)convertView.findViewById(R.id.txt_pic_data);
               holder.textPack = (TextView)convertView.findViewById(R.id.txt_pack_title);
               holder.textPack_data= (TextView)convertView.findViewById(R.id.txt_pack_data);
               holder.chkbox_ack = (CheckBox)convertView.findViewById(R.id.acknowladge_check);
               holder.chkbox_com = (CheckBox)convertView.findViewById(R.id.complete_check);
               convertView.setTag(holder);
           } else {
               holder = (ViewHolder)convertView.getTag();
           }
			
			
			//Get Data From Shared Preferences
			
			Log.e("address_actual[position]complete", address_actual[position]+"-"+complete);
			Log.e("address_actual[position]acknowledged", address_actual[position]+"-"+acknowledged);
			
			boolean pickup_complete = settings.getBoolean(
					address_actual[position]+"-"+complete, false);
			boolean pickup_ack = settings
					.getBoolean(address_actual[position]+"-"+acknowledged, false);
			
			//Get Data From Shared Preferences
			
			holder.chkbox_ack.setChecked(pickup_ack);
			holder.chkbox_com.setChecked(pickup_complete);
			
			String[] allINeed = address_actual[position].split("/");//Make Sure Thaere is no "/" in address
			
			pickup_delivery = allINeed[0];
			title = allINeed[1];
			serial = allINeed[2];
			date = allINeed[3];
			String pic = allINeed[4];
			String jobid = allINeed[5];
			
			//date = allINeed[3]+"-"+allINeed[4]+"-"+allINeed[5];
			
			holder.textView.setText(title);
			holder.textPic_data.setText(pic);
			
			holder.textView_title.setText((pickup_delivery.equals("1"))?"Pickup From :":"Delivery To :");
			
			//List<String> addPrfElements = new ArrayList<String>();
			
			Moil_Package_Update_Service mps = new Moil_Package_Update_Service(holder.textPack_data,holder.textPack,holder.textPic,holder.textPic_data,jobid,pickup_delivery);
			mps.execute(new String[] { "http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx" });
			
			pos = position;
			
			holder.chkbox_ack.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

					if (isChecked) {
						

						if (title.equals("")) {
							Toast.makeText(context,"There Is No "+((pickup_delivery.equals("1"))?"Pickup":"Delivery")+" ",Toast.LENGTH_SHORT).show();
							holder.chkbox_ack.setChecked(false);
						} else {
							Moil_Status_Service mps = new Moil_Status_Service(activity, serial,(pickup_delivery.equals("1"))?"Pickup":"Delivery",acknowledged,date,holder.chkbox_ack,address_actual[pos]+"-"+acknowledged);
							mps.execute(new String[] { "http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx" });
							
							
						}

					}else{
						Moil_Status_Service mps = new Moil_Status_Service(activity, serial,(pickup_delivery.equals("1"))?"Pickup":"Delivery",created,date,holder.chkbox_ack,address_actual[pos]+"-"+acknowledged);
						mps.execute(new String[] { "http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx" });
						
						
					}
					
				}
			});
			
			holder.chkbox_com.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

					if (isChecked) {
						

						if (title.equals("")) {
							Toast.makeText(context,"There Is No "+((pickup_delivery.equals("1"))?"Pickup":"Delivery")+" ",Toast.LENGTH_SHORT).show();
							holder.chkbox_com.setChecked(false);
						} else {
							Moil_Status_Service mps = new Moil_Status_Service(activity, serial,(pickup_delivery.equals("1"))?"Pickup":"Delivery",complete,date,holder.chkbox_com,address_actual[pos]+"-"+complete);
							mps.execute(new String[] { "http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx" });
	
						}

					}else{
						Moil_Status_Service mps = new Moil_Status_Service(activity, serial,(pickup_delivery.equals("1"))?"Pickup":"Delivery",created,date,holder.chkbox_com,address_actual[pos]+"-"+complete);
						mps.execute(new String[] { "http://t2a1.cloudapp.net/TrafficWorkflow/TraficWorkflowWebService.asmx" });
						
						
					}
					
				}
			});

			this.notifyDataSetChanged();

           return convertView;
		}

		@Override
		public int getCount() {
			return address_actual.length;
		}

		@Override
		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}
		
		
	}

	public static class ViewHolder {
       public TextView textView;
       public TextView textView_title;
       public CheckBox chkbox_ack;
       public CheckBox chkbox_com;
       public TextView textPic;
       public TextView textPic_data;
       public TextView textPack;
       public TextView textPack_data;
   }

}
